package com.yanqu.road.server.cmd.rank;

import com.yanqu.road.logic.rank.UnionActivityRankListModel;
import com.yanqu.road.entity.activity.UnionActivityConditionData;
import com.yanqu.road.pb.crossunion.activity.CrossUnionActivityRankDataProto;
import com.yanqu.road.pb.rank.UnionActivityRankProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.union.UnionActivityMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.command.Cmd;

@Cmd(code = Protocol.S_UNION_ACTIVITY_RANK_LIST, desc = "商会活动排行榜")
public class UnionActivityRankListCmd extends AbstractCommand {

    private int activityId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        UnionActivityRankProto.UnionActivityRankListReqMsg reqMsg = UnionActivityRankProto.UnionActivityRankListReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

    }

    @Override
    public void sendData(GamePlayer player) {
        UnionActivityRankProto.UnionActivityRankListRespMsg.Builder respMsg = UnionActivityRankProto.UnionActivityRankListRespMsg.newBuilder();
        respMsg.setActivityId(activityId);
        respMsg.setMyRank(-1);
        respMsg.setValue("0");
        UnionActivityRankListModel rankListModel = UnionActivityMgr.getUnionActivityRankListModel(activityId);
        if (null != rankListModel) {
            respMsg.setRankList(rankListModel.getRankListMsg());
            UnionActivityConditionData unionActivityConditionData = UnionActivityMgr.getUnionActivityConditionData(activityId, player.getUserId());
            if(null != unionActivityConditionData){
                respMsg.setMyRank(rankListModel.getMyRank(unionActivityConditionData.getUnionUid()));
                respMsg.setValue(unionActivityConditionData.getValue().toString());
            }
        }
        player.sendPacket(Protocol.U_UNION_ACTIVITY_RANK_LIST, respMsg);
       /* CrossUnionActivityRankDataProto.CrossUnionActivityDataMsg.Builder msg = CrossUnionActivityRankDataProto.CrossUnionActivityDataMsg.newBuilder();
        msg.setActivityId(activityId);
        msg.setUserId(player.getUserId());
        msg.setConditionType(0);
        msg.setRankListType(1);
        player.sendChannelPacket(CrossProtocol.C_CROSS_UNION_ACTIVITY_RANK_LIST, msg);*/
    }
}
